require 'yaml'
require "ruby/degree.rb"

class String
  def timize()
    self.split(":").map{|t| t.to_f}[0..1]
  end
end

class Array
  def degreefitize
    Degree.new(self[0].to_s.gsub("+","").to_i,self[1].to_i,self[2].to_f )
  end
end


$CONFIG = YAML.load_file("config/config.yml")

libration_positions =  File.open("#{$CONFIG["input"]["lpoint"]}"){|f| f.read}.gsub("\000","").split("\r\n")

$POSITIONS = {}

def position(str)
  hours,minutes = str.timize
  $POSITIONS[hours.to_f][minutes.to_f]
end


$PRECISION = $CONFIG["precision"]

libration_positions.each do |position|
  rows = position.split(" ").compact
  date = rows[0..2].join()
  if date == $CONFIG["input"]["lpoint_date"]
    hours,minutes = rows[3].timize
    alpha = rows[4..6].degreefitize.degretize
    delta = rows[7..9].degreefitize
    $POSITIONS[hours]||={}
    $POSITIONS[hours][minutes]=[alpha,delta]
  end
end


